import { getLodop } from '@/utils/LodopFuncs'

export default {
  methods: {
    initLodop() {
      setTimeout(() => {
        let LODOP = getLodop()
        this.LODOP = LODOP
        let printValue = LODOP.GET_PRINTER_NAME(-1) //获取默认打印机
        let TaskID1, TaskID2
        LODOP.On_Return = function(TaskID, Value) {
          TaskID1 = Value
        }
        TaskID1 = LODOP.GET_VALUE('AO_PRINT_BridgeID', 0)
        setTimeout(() => {
          LODOP.On_Return = function(TaskID, Value) {
            TaskID2 = Value
            LODOP.SET_BRIDGE_INDEX(TaskID1 + ';' + TaskID2, printValue)
          }
          LODOP.GET_VALUE('AO_PRINT_BridgeName', 0)
        }, 500)
      }, 500)
    },
    // 打印商品二维码
    printProductQRCode(item) {
      return new Promise((resolve) => {
        setTimeout(() => {
          this.LODOP.PRINT_INIT('')
          // 纸张大小
          this.LODOP.SET_PRINT_PAGESIZE(1, '75mm', '50mm', '')
          this.LODOP.SET_PRINT_STYLE('Bold', 1)
          this.LODOP.ADD_PRINT_TEXT('2mm', '3mm', '39mm', '4mm', 'REF:' + item.productNo)
          this.LODOP.ADD_PRINT_TEXT('8mm', '3mm', '39mm', '4mm', 'ID:' + item.customerId)
          this.LODOP.ADD_PRINT_TEXT('14mm', '3mm', '39mm', '8mm', 'NAME:' + item.customerCompany)
          this.LODOP.ADD_PRINT_TEXT('24mm', '3mm', '39mm', '8mm', item.name)
          this.LODOP.ADD_PRINT_TEXT('34mm', '3mm', '71mm', '4mm', item.translateName)
          this.LODOP.ADD_PRINT_TEXT('40mm', '3mm', '35mm', '4mm', item.bottomLeft)
          this.LODOP.ADD_PRINT_TEXT('40mm', '44mm', '30mm', '4mm', item.productBarcode)
          this.LODOP.ADD_PRINT_BARCODE('2mm', '42mm', '36mm', '36mm', 'QRCode', item.barCodeId)
          //直接打印
           this.LODOP.PRINT()
          //预览打印
          //this.LODOP.PREVIEW()
        }, 1000)
      })
    },
    // 打印箱子二维码
    printBoxQRCode(item){
      return new Promise((resolve) => {
        setTimeout(() => {
          this.LODOP.PRINT_INIT('')
          // 纸张大小
          this.LODOP.SET_PRINT_PAGESIZE(1, '100mm', '150mm', '')
          this.LODOP.SET_PRINT_STYLE('FontSize', 14)
          this.LODOP.SET_PRINT_STYLE('Bold', 1)
          this.LODOP.ADD_PRINT_TEXT('10mm', '5mm', '90mm', '5mm', '客户名称:' + item.customerName)
          this.LODOP.ADD_PRINT_BARCODE('20mm', '10mm', '80mm', '80mm', 'QRCode', item.id)
           this.LODOP.ADD_PRINT_TEXT('95mm', '5mm', '90mm', '5mm', '订单编号:' + item.orderNo)
           this.LODOP.ADD_PRINT_TEXT('105mm', '5mm', '90mm', '5mm', '子订单编号:' + item.childNo)
           this.LODOP.ADD_PRINT_TEXT('115mm', '5mm', '90mm', '5mm', '内含总包数:' + item.contains)
          //直接打印
           this.LODOP.PRINT()
          //预览打印
          // this.LODOP.PREVIEW()
        }, 1000)
      })
    },
  },
  mounted() {
    this.initLodop()
  }
}
